package handlers

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"xiao-hong-book/models"
)

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size
	var book []models.Book
	err := models.DB.Offset(offset).Limit(size).Find(&book).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询失败",
		"data": book,
	})
}
